package main

import "fmt"

/**
  地址：https://leetcode-cn.com/problems/two-sum/
*/
func twoSum(nums []int, target int) []int {
	// map: key -> 输入的整数，value -> 数组下标
	tmpMap := make(map[int]int)
	for index, num := range nums {
		another := target - num // 期望的另一个整数
		if anoIndex, ok := tmpMap[another]; ok {
			return []int{anoIndex, index}
		}
		tmpMap[num] = index // (当前整数，下标)
	}
	return []int{}
}

func main() {
	fmt.Println(twoSum([]int{2, 7, 11, 15}, 9))
	fmt.Println(twoSum([]int{3, 2, 4}, 6))
	fmt.Println(twoSum([]int{3, 3}, 6))
}
